package com.art.sunflower.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface RsgrMapper {

    @Insert("insert into rsgr(title, introduce, startTime, endTime) values(#{title}, #{introduce}, #{startTime}, #{endTime})")
    void insertRsgr(String title, String introduce, String startTime, String endTime);

    @Insert("insert into rsgr_classes(rsgr_id, classes_id) values(#{rsgrId}, #{classesId})")
    void insertRsgrClasses(Integer rsgrId, Integer classesId);

    @Select("select * from rsgr where id = #{id}")
    Map<String, Object> selectRsgr(Integer id);

    @Delete("delete from rsgr where id = #{id}")
    void delete(Integer id);

    @Update("update rsgr set title = #{title}, introduce = #{introduce}, startTime = #{startTime}, endTime = #{endTime} where id = #{id}")
    void updateRsgr(Integer id, String title, String introduce, String startTime, String endTime);

    @Delete("delete from rsgr_classes where rsgr_id = #{id}")
    void deleteClasses(Integer id);

    @Select("select * from rsgr")
    List<Map<String, Object>> selectList();

    @Select("select classes_id from rsgr_classes where id = #{id}")
    List<Integer> selectClasserId(Integer id);

    @Select("select * from rsgr_information_view where id = #{id}")
    Map<String, Object> selectAllRsgr(Integer id);

}
